import { initMapStyle } from '@/utils/mineMap/mapStyle.js'
class MapInit {
  constructor(domId, options) {
    let longitude = import.meta.env.VITE_MAP_CENTER_LONGITUDE
    let latitude = import.meta.env.VITE_MAP_CENTER_LATITUDE
    let mineMap = initMapStyle(window.minemap)
    this.map3d = new mineMap.Map(
      Object.assign(
        {
          container: domId,
          style: mineMap.mapStyle,
          center: [longitude, latitude],
          zoom: 14,
          pitch: 0,
          rotation: 0,
          maxZoom: 19,
          logoControl: false,
          projection: 'MERCATOR'
        },
        options
      )
    )
    this.map3d.loadMapImgs = imgList => {
      imgList.forEach(img => {
        this.map3d.loadImage(img.src, (error, image) => {
          if (!image) {
            return
          }
          this.map3d.addImage(img.id, image)
        })
      })
    }
    return this.map3d
  }
}
export default MapInit
